//
//  HMUIbarbuttonItem.swift
//  swift微博项目
//
//  Created by huodian on 16/9/22.
//  Copyright © 2016年 huodian. All rights reserved.
//

import UIKit
extension UIBarButtonItem {


    
    convenience init(title:String = "",imageNamed:String? = nil,target:Any?,action:Selector) {
        
        let btn = UIButton()
        
        btn.setTitle(title, for: UIControlState.normal)
        
        btn.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
        
         btn.setTitleColor(UIColor.orange, for: UIControlState.highlighted)
        
        if imageNamed != nil {
            btn.setImage(UIImage(named:imageNamed!), for: UIControlState.normal)
            
            btn.setImage(UIImage(named:imageNamed! + "_highlighted"), for: UIControlState.highlighted)
            

        }
        
               btn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        
        btn.addTarget(target, action:action, for: UIControlEvents.touchUpInside)
       
        
        
        btn.sizeToFit()
        
        self.init()
        
        self.customView = btn
        
    
        
    }
 
    
    
    
}
